/*
 * Copyright © 2011 SenseForce.com.
 * The Software shall be used for Good, not Evil.
 */

package com.senseforce.midlets;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.senseforce.classes.PhoneBookConfig;
import com.senseforce.classes.PhoneBookWelcomeCanvas;
import com.senseforce.classes.PhoneBookList;
import com.senseforce.classes.PhoneBookAddForm;

/**
 * @author jcccn
 * @site http://www.senseforce.com/
 */
public class PhoneBook extends MIDlet {
	private Display display;
	private PhoneBookWelcomeCanvas welcomeForm = null;
	private PhoneBookList listForm = null;
	private PhoneBookAddForm addForm = null;
    public void startApp() {
		display = Display.getDisplay(this);
		changeForm(PhoneBookConfig.FORMTYPE_WELCOME);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
	
	public void changeForm(int formType) {
		switch(formType) {
			case PhoneBookConfig.FORMTYPE_WELCOME:
				if (welcomeForm == null) {
					welcomeForm = new PhoneBookWelcomeCanvas(this);
				}
				display.setCurrent(welcomeForm);
				break;
				
			case PhoneBookConfig.FORMTYPE_PHONELIST:
				if (listForm == null) {
					listForm = new PhoneBookList(this);
				}
				display.setCurrent(listForm);
				listForm.refresh();
				break;
				
			case PhoneBookConfig.FORMTYPE_PHONEADD:
				if (addForm == null) {
					addForm = new PhoneBookAddForm(this);
				}
				display.setCurrent(addForm);
				addForm.refresh();
				break;
			
			default:
				break;
		}
	}
}
